<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
                                                                                                          <el-form-item label="日批日期" prop="batchJobDate">
                    <el-date-picker clearable size="small"
                                    v-model="queryParams.batchJobDate"
                                    type="date"
                                    value-format="yyyy-MM-dd"
                                    placeholder="选择日批日期">
                    </el-date-picker>
                  </el-form-item>
                                                                                                                  <el-form-item label="贷款流水号" prop="loanSerialNo">
                    <el-input
                        v-model="queryParams.loanSerialNo"
                        placeholder="请输入贷款流水号"
                        clearable
                        size="small"
                        @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
                                                                                                                  <el-form-item label="客户号" prop="custNo">
                    <el-input
                        v-model="queryParams.custNo"
                        placeholder="请输入客户号"
                        clearable
                        size="small"
                        @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
                                                                                                                                                                                                                                                                                                      <el-form-item label="还款日期" prop="repayDate">
                    <el-input
                        v-model="queryParams.repayDate"
                        placeholder="请输入还款日期"
                        clearable
                        size="small"
                        @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
                                                                                                                                                                                                                                                                                  <el-form-item label="借据状态" prop="iouStatus">
                    <el-input
                        v-model="queryParams.iouStatus"
                        placeholder="请输入借据状态"
                        clearable
                        size="small"
                        @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
                                                                                                                  <el-form-item label="失败有效状态" prop="failState">
                    <el-input
                        v-model="queryParams.failState"
                        placeholder="请输入失败有效状态"
                        clearable
                        size="small"
                        @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
                                                                                                                  <el-form-item label="状态" prop="state">
                    <el-input
                        v-model="queryParams.state"
                        placeholder="请输入状态"
                        clearable
                        size="small"
                        @keyup.enter.native="handleQuery"
                    />
                  </el-form-item>
                                                                                                      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['business:DateBatchFailLoan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['business:DateBatchFailLoan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['business:DateBatchFailLoan:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['business:DateBatchFailLoan:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="DateBatchFailLoanList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
                                                          <el-table-column label="PK" align="center" prop="id" />
                                                                      <el-table-column label="日批日期" align="center" prop="batchJobDate" width="180">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.batchJobDate, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>
                                                                      <el-table-column label="贷款流水号" align="center" prop="loanSerialNo" />
                                                                      <el-table-column label="客户号" align="center" prop="custNo" />
                                                                      <el-table-column label="借款金额" align="center" prop="loanAmt" />
                                                                      <el-table-column label="趸交" align="center" prop="isSinglePayment" />
                                                                      <el-table-column label="期数" align="center" prop="periodNum" />
                                                                      <el-table-column label="单位" align="center" prop="unit" />
                                                                      <el-table-column label="利(息)率" align="center" prop="interestRate" />
                                                                      <el-table-column label="滞纳金日费率" align="center" prop="dateLateFee" />
                                                                      <el-table-column label="滞纳金按日收费宽限期" align="center" prop="lateFeeGracePeriod" />
                                                                      <el-table-column label="放款本金" align="center" prop="loanPrincipal" />
                                                                      <el-table-column label="已还本金" align="center" prop="repaidPrincipal" />
                                                                      <el-table-column label="还款日期" align="center" prop="repayDate" />
                                                                      <el-table-column label="服务费" align="center" prop="serviceFee" />
                                                                      <el-table-column label="已还服务费" align="center" prop="repaidServiceFee" />
                                                                      <el-table-column label="总利息" align="center" prop="loanInterest" />
                                                                      <el-table-column label="已还总利息" align="center" prop="repaidInterest" />
                                                                      <el-table-column label="减免金额" align="center" prop="feeRemissionAmt" />
                                                                      <el-table-column label="滞纳金" align="center" prop="lateFee" />
                                                                      <el-table-column label="已还滞纳金" align="center" prop="repaidLateFee" />
                                                                      <el-table-column label="逾期金额" align="center" prop="overdueAmount" />
                                                                      <el-table-column label="借据状态" align="center" prop="iouStatus" />
                                                                      <el-table-column label="失败有效状态" align="center" prop="failState" />
                                                                      <el-table-column label="状态" align="center" prop="state" />
                                                                      <el-table-column label="备注" align="center" prop="remark" />
                                                                                                                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['business:DateBatchFailLoan:edit']"
          >修改</el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['business:DateBatchFailLoan:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改日批失败借据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                                                                                                                                                            <el-form-item label="日批日期" prop="batchJobDate">
                          <el-date-picker clearable size="small"
                                          v-model="form.batchJobDate"
                                          type="date"
                                          value-format="yyyy-MM-dd"
                                          placeholder="选择日批日期">
                          </el-date-picker>
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="贷款流水号" prop="loanSerialNo">
                          <el-input v-model="form.loanSerialNo" placeholder="请输入贷款流水号" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="客户号" prop="custNo">
                          <el-input v-model="form.custNo" placeholder="请输入客户号" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="借款金额" prop="loanAmt">
                          <el-input v-model="form.loanAmt" placeholder="请输入借款金额" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="趸交" prop="isSinglePayment">
                          <el-input v-model="form.isSinglePayment" placeholder="请输入趸交" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="期数" prop="periodNum">
                          <el-input v-model="form.periodNum" placeholder="请输入期数" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="单位" prop="unit">
                          <el-input v-model="form.unit" placeholder="请输入单位" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="利(息)率" prop="interestRate">
                          <el-input v-model="form.interestRate" placeholder="请输入利(息)率" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="滞纳金日费率" prop="dateLateFee">
                          <el-input v-model="form.dateLateFee" placeholder="请输入滞纳金日费率" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="滞纳金按日收费宽限期" prop="lateFeeGracePeriod">
                          <el-input v-model="form.lateFeeGracePeriod" placeholder="请输入滞纳金按日收费宽限期" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="放款本金" prop="loanPrincipal">
                          <el-input v-model="form.loanPrincipal" placeholder="请输入放款本金" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="已还本金" prop="repaidPrincipal">
                          <el-input v-model="form.repaidPrincipal" placeholder="请输入已还本金" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="还款日期" prop="repayDate">
                          <el-input v-model="form.repayDate" placeholder="请输入还款日期" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="服务费" prop="serviceFee">
                          <el-input v-model="form.serviceFee" placeholder="请输入服务费" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="已还服务费" prop="repaidServiceFee">
                          <el-input v-model="form.repaidServiceFee" placeholder="请输入已还服务费" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="总利息" prop="loanInterest">
                          <el-input v-model="form.loanInterest" placeholder="请输入总利息" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="已还总利息" prop="repaidInterest">
                          <el-input v-model="form.repaidInterest" placeholder="请输入已还总利息" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="减免金额" prop="feeRemissionAmt">
                          <el-input v-model="form.feeRemissionAmt" placeholder="请输入减免金额" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="滞纳金" prop="lateFee">
                          <el-input v-model="form.lateFee" placeholder="请输入滞纳金" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="已还滞纳金" prop="repaidLateFee">
                          <el-input v-model="form.repaidLateFee" placeholder="请输入已还滞纳金" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="逾期金额" prop="overdueAmount">
                          <el-input v-model="form.overdueAmount" placeholder="请输入逾期金额" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="借据状态" prop="iouStatus">
                          <el-input v-model="form.iouStatus" placeholder="请输入借据状态" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="失败有效状态" prop="failState">
                          <el-input v-model="form.failState" placeholder="请输入失败有效状态" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="状态" prop="state">
                          <el-input v-model="form.state" placeholder="请输入状态" />
                        </el-form-item>
                                                                                                                                                                                          <el-form-item label="备注" prop="remark">
                          <el-input v-model="form.remark" placeholder="请输入备注" />
                        </el-form-item>
                                                                                                                                                                                                </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listDateBatchFailLoan, getDateBatchFailLoan, delDateBatchFailLoan, addDateBatchFailLoan, updateDateBatchFailLoan, exportDateBatchFailLoan } from "@/api/business/DateBatchFailLoan";
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  export default {
    name: "DateBatchFailLoan",
    components: {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
                  // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 日批失败借据表格数据
              DateBatchFailLoanList: [],
                  // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
                                                                                batchJobDate: null,
                                                                    loanSerialNo: null,
                                                                    custNo: null,
                                                                                                                                                                                                                                                                                                                                repayDate: null,
                                                                                                                                                                                                                                                                                                    iouStatus: null,
                                                                    failState: null,
                                                                    state: null,
                                                                                                                        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
                                                                                                                        batchJobDate: [
                    { required: true, message: "日批日期不能为空", trigger: "blur" }
                  ],
                                                                                                            loanSerialNo: [
                    { required: true, message: "贷款流水号不能为空", trigger: "blur" }
                  ],
                                                                                                            custNo: [
                    { required: true, message: "客户号不能为空", trigger: "blur" }
                  ],
                                                                                                                                                                                                                                                                                                                                                                        repayDate: [
                    { required: true, message: "还款日期不能为空", trigger: "blur" }
                  ],
                                                                                                                                                                                                                                                                                                                                                                                                                                                            createTime: [
                    { required: true, message: "创建时间不能为空", trigger: "blur" }
                  ],
                                                                                                            updateTime: [
                    { required: true, message: "更新时间不能为空", trigger: "blur" }
                  ]
                                    }
      };
    },
    created() {
      this.getList();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            },
    methods: {
      /** 查询日批失败借据列表 */
      getList() {
        this.loading = true;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            listDateBatchFailLoan(this.queryParams).then(response => {
          this.DateBatchFailLoanList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
                                                    id: null,
                                                                    batchJobDate: null,
                                                                    loanSerialNo: null,
                                                                    custNo: null,
                                                                    loanAmt: null,
                                                                    isSinglePayment: null,
                                                                    periodNum: null,
                                                                    unit: null,
                                                                    interestRate: null,
                                                                    dateLateFee: null,
                                                                    lateFeeGracePeriod: null,
                                                                    loanPrincipal: null,
                                                                    repaidPrincipal: null,
                                                                    repayDate: null,
                                                                    serviceFee: null,
                                                                    repaidServiceFee: null,
                                                                    loanInterest: null,
                                                                    repaidInterest: null,
                                                                    feeRemissionAmt: null,
                                                                    lateFee: null,
                                                                    repaidLateFee: null,
                                                                    overdueAmount: null,
                                                                    iouStatus: null,
                                                                    failState: null,
                                                                    state: null,
                                                                    remark: null,
                                                                    createTime: null,
                                                                    updateTime: null
                                    };
                  this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加日批失败借据";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getDateBatchFailLoan(id).then(response => {
          this.form = response.data;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  this.open = true;
          this.title = "修改日批失败借据";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        if (this.form.id != null) {
              updateDateBatchFailLoan(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addDateBatchFailLoan(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除日批失败借据编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDateBatchFailLoan(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
              /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有日批失败借据数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDateBatchFailLoan(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
</script>
